/*
 * table_Declaration.c
 *
 *  Created on: 2012/04/26
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

typedef struct _DECLARATIONTBL {
	AST		astTypeSpecifier;		/* 2 */
	AST		astDeclarator;			/* 3 */
	AST		astLocation;				/* 4 */
	U2	usParentKind;				/* 5 */
	U2	usResultKind;				/* 6 */
	AST astParent;							/* 7 */
	AST	astTranslationUnit;			/* 9 */
	AST astNext;
}DECLARATION, *PDECLARATION;

#define TableSize  (sizeof(DECLARATION))
#define TableType  PDECLARATION
#define stTable stDeclarationManager.memoryBlocks
#define maxTable stDeclarationManager.maxRecordNum
#define  maxNumPerBlk  (stDeclarationManager.astMaxNum_Block)

static TABLEMANAGER stDeclarationManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stDeclarationManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stDeclarationManager, resetListener, index );
	if( temp != NULL ){
		if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
	}
	return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stDeclarationManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stDeclarationManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stDeclarationManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}

static AST getTypeSpecifier( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTypeSpecifier;
}
static AST setTypeSpecifier( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTypeSpecifier = value;
}
static AST getDeclarator( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDeclarator;
}
static AST setDeclarator( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDeclarator = value;
}
static AST getCodeScp( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLocation;
}
static AST setCodeScp( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLocation = value;
}
static U2 getParentKind( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usParentKind;
}
static U2 setParentKind( AST index, U2 value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usParentKind = value;
}
static U2 getNameSpace( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usResultKind;
}
static U2 setNameSpace( AST index, U2 value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usResultKind = value;
}
static AST getParent( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent;
}
static AST setParent( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent = value;
}
static AST getTranUnit( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTranslationUnit;
}
static AST setTranUnit( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTranslationUnit = value;
}
static AST getNext( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext;
}
static AST setNext( AST index, AST value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext = value;
}


const DECLARATIONACCESS stDeclarationAccess={
		//		BOOL (*clear)( VOID );
				ClearTable,
		//		BOOL (*reset)( VOID );
				ResetTable,
		//		BOOL (*alloc)( AST );
				AllocTable,
		//		AST  (*getMax)( VOID );
				getMaxLineNum,
//		ACCESS_IDX_FIELD  typeSpecifier;
				{
						getTypeSpecifier,
						setTypeSpecifier
				},
//		ACCESS_IDX_FIELD  declarator;
				{
						getDeclarator,
						setDeclarator
				},
//		ACCESS_IDX_FIELD  codeScp;
				{
						getCodeScp,
						setCodeScp
				},
//		ACCESS_U2_FIELD   parentKind;
				{
						getParentKind,
						setParentKind
				},
				{
						getNameSpace,
						setNameSpace
				},
//		ACCESS_IDX_FIELD  parentIdx;
				{
						getParent,
						setParent
				},
//		ACCESS_IDX_FIELD translationUnit;
				{
						getTranUnit,
						setTranUnit
				},
//		ACCESS_IDX_FIELD  next;
				{
						getNext,
						setNext
				}
};
